package com.hpu.callback;

import android.os.Handler;
import android.os.Message;

import com.hpu.constants.HttpConstants;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

/**
 * 实现了期末成绩业务类的回调接口
 * 
 * @author Administrator
 * 
 */
public class ImageCallback implements Callback {

	private Handler handler;

	public ImageCallback(Handler handler) {
		this.handler = handler;
	}

	@Override
	public void onFailure(Call arg0, IOException arg1) {
		handler.sendEmptyMessage(HttpConstants.DOWNLOAD_IMAGE_ERROR);
	}

	@Override
	public void onResponse(Call arg0, Response arg1) throws IOException {
		byte[] bytes=arg1.body().bytes();
		String result=new String(bytes);
			Message message = new Message();
			message.what = HttpConstants.DOWNLOAD_IMAGE_SUCCESS;
			message.obj = bytes;
			handler.sendMessage(message);
	}

}
